package com.rybbaby.tss.front.tssCourse.dao.imp;

import com.rybbaby.tss.core.utils.StringUtils;
import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssCourse.dao.ITssCourseDao;
import com.rybbaby.tss.front.tssCourse.entity.TssCourse;
import org.apache.poi.util.StringUtil;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 雷春琼
 * @description 课程表数据库操作实现
 * @createDate 2017-08-10 下午7:57:36
 */
@Repository
public class TssCourseDaoImp extends GenericDao<TssCourse> implements ITssCourseDao {

    /**
     * 根据状态修改课程信息
     *
     * @param targetDateId
     * @param isBlockUp
     * @return
     */
    @Override
    public Integer updateCourseByIsBlockUp(String targetDateId, Boolean isBlockUp) {
        return this.executeSql("update tss_course set updateTime=Now(),isBlockUp=? where id=?", new Object[]{isBlockUp, targetDateId});

    }

    @Override
    public List<Map<String, Object>> queryListBySystemPid(String systemPid,Integer type,String ids) {
        List<Map<String, Object>> tssCourseList = new ArrayList<>();
        StringBuffer sql = new StringBuffer();
        if (StringUtils.isBlank(systemPid)) {
            sql.append("select tc.id,tc.systemPid,cs.`name`   from tss_course tc  LEFT JOIN sys_course_system cs\n" +
                    "on cs.pId=tc.systemPid where tc.type=? and adminUserId in ('"+ids+"')  GROUP BY tc.systemPid ");
            tssCourseList=this.findForJdbc(sql.toString(), new Object[]{type});
        } else {
            sql.append("select tc.id,tc.systemId,cs.`name` from tss_course tc  LEFT JOIN sys_course_system cs\n" +
                    "on cs. id=tc.systemId where tc.systemPid=?  and tc.type=?  and adminUserId in ('"+ids+"')  ");
            tssCourseList=this.findForJdbc(sql.toString(),new Object[]{systemPid,type} );
        }
        return tssCourseList;
    }
}
